package com.getpebble.android.common.model;

import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable.Creator;

public class FrameworkState implements Parcelable {
    public static final Creator<FrameworkState> CREATOR = new Creator<FrameworkState>() {
        public FrameworkState createFromParcel(Parcel in) {
            return new FrameworkState(in);
        }

        public FrameworkState[] newArray(int size) {
            return new FrameworkState[size];
        }
    };
    private static final String TAG = FrameworkState.class.getSimpleName();
    private AppInfo mAppInfo;
    private int mAppInstallProgress;
    private int mAppInstallResult;
    private int mAppRemoveResult;
    private boolean mAppUpgradeResult;
    private String mCoreDumpFilename;
    private int mCoreDumpResult;
    private String mDevConnIpAddress;
    private boolean mDevConnIsConnected;
    private boolean mDevConnProxyConnected;
    private int mFileInstallProgress;
    int mFileInstallResult;
    private String mFileInstallUri;
    private int mFirmwareInstallProgress;
    private int mFirmwareInstallResult;
    private boolean mIsBluetoothEnabled;
    private boolean mIsDiscoveryInProgress;
    private EventType mLastEvent;
    private String mLogDumpFilename;
    private int mLogDumpResult;
    private boolean mNotificationDemoResult;
    private boolean mPebbleTimeConnected;
    private StateListener mStateListener;

    public enum EventType {
        DISCOVERY_STATE_CHANGED,
        BLUETOOTH_STATE_CHANGED,
        FIRMWARE_INSTALL_PROGRESS_CHANGED,
        FIRMWARE_INSTALL_STATE_CHANGED,
        NOTIFICATION_DEMO_COMPLETE,
        APP_INSTALL_COMPLETE,
        APP_INSTALL_PROGRESS_CHANGED,
        APP_REMOVE_COMPLETE,
        APP_UPGRADE_COMPLETE,
        APP_INFO_AVAILABLE,
        FILE_INSTALL_COMPLETE,
        FILE_INSTALL_PROGRESS_CHANGED,
        CORE_DUMP_COMPLETE,
        LOG_DUMP_COMPLETE,
        LOG_CORE_DUMP_PING,
        DEVELOPER_CONNECTION_CHANGED,
        PEBBLE_TIME_CONNECTED
    }

    public interface StateListener {
        void onStateChanged();
    }

    public FrameworkState(boolean isDiscoveryInProgress, boolean isBluetoothEnabled, StateListener stateListener) {
        this.mFirmwareInstallResult = -12;
        this.mAppInstallResult = -14;
        this.mAppInstallProgress = 0;
        this.mAppRemoveResult = 5;
        this.mAppUpgradeResult = false;
        this.mAppInfo = null;
        this.mFileInstallResult = -1;
        this.mFileInstallUri = null;
        this.mFileInstallProgress = 0;
        this.mCoreDumpResult = -10;
        this.mCoreDumpFilename = null;
        this.mLogDumpResult = 0;
        this.mLogDumpFilename = null;
        this.mDevConnIpAddress = null;
        this.mDevConnIsConnected = false;
        this.mDevConnProxyConnected = false;
        this.mPebbleTimeConnected = false;
        this.mIsDiscoveryInProgress = isDiscoveryInProgress;
        this.mIsBluetoothEnabled = isBluetoothEnabled;
        this.mStateListener = stateListener;
    }

    public FrameworkState(FrameworkState frameworkState) {
        this.mFirmwareInstallResult = -12;
        this.mAppInstallResult = -14;
        this.mAppInstallProgress = 0;
        this.mAppRemoveResult = 5;
        this.mAppUpgradeResult = false;
        this.mAppInfo = null;
        this.mFileInstallResult = -1;
        this.mFileInstallUri = null;
        this.mFileInstallProgress = 0;
        this.mCoreDumpResult = -10;
        this.mCoreDumpFilename = null;
        this.mLogDumpResult = 0;
        this.mLogDumpFilename = null;
        this.mDevConnIpAddress = null;
        this.mDevConnIsConnected = false;
        this.mDevConnProxyConnected = false;
        this.mPebbleTimeConnected = false;
        this.mStateListener = null;
        this.mLastEvent = frameworkState.mLastEvent;
        this.mIsDiscoveryInProgress = frameworkState.mIsDiscoveryInProgress;
        this.mIsBluetoothEnabled = frameworkState.mIsBluetoothEnabled;
        this.mFirmwareInstallProgress = frameworkState.mFirmwareInstallProgress;
        this.mFirmwareInstallResult = frameworkState.mFirmwareInstallResult;
        this.mNotificationDemoResult = frameworkState.mNotificationDemoResult;
        this.mAppInstallResult = frameworkState.mAppInstallResult;
        this.mAppInstallProgress = frameworkState.mAppInstallProgress;
        this.mAppRemoveResult = frameworkState.mAppRemoveResult;
        this.mAppUpgradeResult = frameworkState.mAppUpgradeResult;
        this.mAppInfo = frameworkState.mAppInfo;
        this.mFileInstallResult = frameworkState.mFileInstallResult;
        this.mFileInstallUri = frameworkState.mFileInstallUri;
        this.mFileInstallProgress = frameworkState.mFileInstallProgress;
        this.mCoreDumpFilename = frameworkState.mCoreDumpFilename;
        this.mCoreDumpResult = frameworkState.mCoreDumpResult;
        this.mLogDumpFilename = frameworkState.mLogDumpFilename;
        this.mLogDumpResult = frameworkState.mLogDumpResult;
        this.mDevConnIpAddress = frameworkState.mDevConnIpAddress;
        this.mDevConnIsConnected = frameworkState.mDevConnIsConnected;
        this.mDevConnProxyConnected = frameworkState.mDevConnProxyConnected;
        this.mPebbleTimeConnected = frameworkState.mPebbleTimeConnected;
    }

    public EventType getLastEvent() {
        return this.mLastEvent;
    }

    public void setStateListener(StateListener stateListener) {
        this.mStateListener = stateListener;
    }

    public synchronized boolean isDiscoveryInProgress() {
        return this.mIsDiscoveryInProgress;
    }

    public synchronized void setDiscoveryInProgress(boolean isInProgress) {
        if (this.mIsDiscoveryInProgress != isInProgress) {
            this.mIsDiscoveryInProgress = isInProgress;
            this.mLastEvent = EventType.DISCOVERY_STATE_CHANGED;
            notifyListener();
        }
    }

    public synchronized boolean isBluetoothEnabled() {
        return this.mIsBluetoothEnabled;
    }

    public synchronized void setIsBluetoothEnabled(boolean isBluetoothEnabled) {
        if (this.mIsBluetoothEnabled != isBluetoothEnabled) {
            this.mIsBluetoothEnabled = isBluetoothEnabled;
            this.mLastEvent = EventType.BLUETOOTH_STATE_CHANGED;
            notifyListener();
        }
    }

    public synchronized int getFirmwareInstallProgress() {
        return this.mFirmwareInstallProgress;
    }

    public synchronized void setFirmwareInstallProgress(int firmwareInstallProgress) {
        this.mFirmwareInstallProgress = firmwareInstallProgress;
        this.mLastEvent = EventType.FIRMWARE_INSTALL_PROGRESS_CHANGED;
        notifyListener();
    }

    public synchronized int getFirmwareInstallResult() {
        return this.mFirmwareInstallResult;
    }

    public synchronized void setFirmwareInstallResult(int firmwareInstallResult) {
        this.mFirmwareInstallResult = firmwareInstallResult;
        this.mLastEvent = EventType.FIRMWARE_INSTALL_STATE_CHANGED;
        notifyListener();
    }

    public synchronized boolean isNotificationDemoSuccess() {
        return this.mNotificationDemoResult;
    }

    public synchronized void setNotificationDemoResult(boolean success) {
        this.mNotificationDemoResult = success;
        this.mLastEvent = EventType.NOTIFICATION_DEMO_COMPLETE;
        notifyListener();
    }

    public synchronized int getAppInstallResult() {
        return this.mAppInstallResult;
    }

    public synchronized void setAppInstallResult(int appInstallResult) {
        this.mAppInstallResult = appInstallResult;
        this.mLastEvent = EventType.APP_INSTALL_COMPLETE;
        notifyListener();
    }

    public synchronized int getAppInstallProgress() {
        return this.mAppInstallProgress;
    }

    public synchronized void setAppInstallProgress(int appInstallProgress) {
        this.mAppInstallProgress = appInstallProgress;
        this.mLastEvent = EventType.APP_INSTALL_PROGRESS_CHANGED;
        notifyListener();
    }

    public synchronized int getAppRemoveResult() {
        return this.mAppRemoveResult;
    }

    public synchronized void setAppRemoveResult(int appRemoveResult) {
        this.mAppRemoveResult = appRemoveResult;
        this.mLastEvent = EventType.APP_REMOVE_COMPLETE;
        notifyListener();
    }

    public synchronized void setAppUpgradeResult(boolean appUpgradeResult) {
        this.mAppUpgradeResult = appUpgradeResult;
        this.mLastEvent = EventType.APP_UPGRADE_COMPLETE;
        notifyListener();
    }

    public synchronized AppInfo getAppInfo() {
        return this.mAppInfo;
    }

    public synchronized void setAppInfo(AppInfo appInfo) {
        this.mAppInfo = appInfo;
        this.mLastEvent = EventType.APP_INFO_AVAILABLE;
        notifyListener();
    }

    public synchronized int getFileInstallResult() {
        return this.mFileInstallResult;
    }

    public synchronized void setFileInstallResult(int result, Uri installedFileUri) {
        this.mFileInstallResult = result;
        this.mFileInstallUri = installedFileUri == null ? null : installedFileUri.toString();
        this.mLastEvent = EventType.FILE_INSTALL_COMPLETE;
        notifyListener();
    }

    public synchronized int getFileInstallProgress() {
        return this.mFileInstallProgress;
    }

    public synchronized void setFileInstallProgress(int progress) {
        this.mLastEvent = EventType.FILE_INSTALL_PROGRESS_CHANGED;
        this.mFileInstallProgress = progress;
        notifyListener();
    }

    public synchronized int getCoreDumpResult() {
        return this.mCoreDumpResult;
    }

    public synchronized String getCoreDumpFilename() {
        return this.mCoreDumpFilename;
    }

    public synchronized void setCoreDumpResult(int result, String filename) {
        this.mCoreDumpResult = result;
        this.mCoreDumpFilename = filename;
        this.mLastEvent = EventType.CORE_DUMP_COMPLETE;
        notifyListener();
    }

    public synchronized int getLogDumpResult() {
        return this.mLogDumpResult;
    }

    public synchronized String getLogDumpFilename() {
        return this.mLogDumpFilename;
    }

    public synchronized void setLogDumpResult(int result, String filename) {
        this.mLogDumpResult = result;
        this.mLogDumpFilename = filename;
        this.mLastEvent = EventType.LOG_DUMP_COMPLETE;
        notifyListener();
    }

    public synchronized void sendLogCoreDumpPing() {
        this.mLastEvent = EventType.LOG_CORE_DUMP_PING;
        notifyListener();
    }

    public synchronized String getDeveloperConnectionIpAddress() {
        return this.mDevConnIpAddress;
    }

    public synchronized void setDeveloperConnectionIpAddress(String ipAddress) {
        this.mDevConnIpAddress = ipAddress;
        this.mLastEvent = EventType.DEVELOPER_CONNECTION_CHANGED;
        notifyListener();
    }

    public synchronized boolean isDeveloperConnectionConnected() {
        return this.mDevConnIsConnected;
    }

    public synchronized void setDeveloperConnectionConnected(boolean isConnected) {
        this.mDevConnIsConnected = isConnected;
        this.mLastEvent = EventType.DEVELOPER_CONNECTION_CHANGED;
        notifyListener();
    }

    public synchronized boolean isDeveloperConnectionProxyConnected() {
        return this.mDevConnProxyConnected;
    }

    public synchronized void setDeveloperConnectionProxyConnected(boolean isConnected) {
        this.mDevConnProxyConnected = isConnected;
        this.mLastEvent = EventType.DEVELOPER_CONNECTION_CHANGED;
        notifyListener();
    }

    public synchronized boolean getPebbleTimeConnected() {
        return this.mPebbleTimeConnected;
    }

    public synchronized void setPebbleTimeConnected(boolean pebbleTimeConnected) {
        this.mPebbleTimeConnected = pebbleTimeConnected;
        this.mLastEvent = EventType.PEBBLE_TIME_CONNECTED;
        notifyListener();
    }

    private void notifyListener() {
        if (this.mStateListener != null) {
            this.mStateListener.onStateChanged();
        }
    }

    public int describeContents() {
        return 0;
    }

    public void writeToParcel(Parcel dest, int flags) {
        int i;
        int i2 = 1;
        dest.writeSerializable(this.mLastEvent);
        dest.writeByte((byte) (this.mIsDiscoveryInProgress ? 1 : 0));
        if (this.mIsBluetoothEnabled) {
            i = 1;
        } else {
            i = 0;
        }
        dest.writeByte((byte) i);
        dest.writeInt(this.mFirmwareInstallProgress);
        dest.writeInt(this.mFirmwareInstallResult);
        if (this.mNotificationDemoResult) {
            i = 1;
        } else {
            i = 0;
        }
        dest.writeByte((byte) i);
        dest.writeInt(this.mAppInstallResult);
        dest.writeInt(this.mAppInstallProgress);
        dest.writeInt(this.mAppRemoveResult);
        if (this.mAppUpgradeResult) {
            i = 1;
        } else {
            i = 0;
        }
        dest.writeByte((byte) i);
        dest.writeParcelable(this.mAppInfo, 0);
        dest.writeInt(this.mFileInstallResult);
        dest.writeString(this.mFileInstallUri);
        dest.writeInt(this.mFileInstallProgress);
        dest.writeInt(this.mCoreDumpResult);
        dest.writeString(this.mCoreDumpFilename);
        dest.writeInt(this.mLogDumpResult);
        dest.writeString(this.mLogDumpFilename);
        dest.writeString(this.mDevConnIpAddress);
        dest.writeByte((byte) (this.mDevConnIsConnected ? 1 : 0));
        if (this.mDevConnProxyConnected) {
            i = 1;
        } else {
            i = 0;
        }
        dest.writeByte((byte) i);
        if (!this.mPebbleTimeConnected) {
            i2 = 0;
        }
        dest.writeByte((byte) i2);
    }

    private FrameworkState(Parcel in) {
        boolean z;
        boolean z2 = true;
        this.mFirmwareInstallResult = -12;
        this.mAppInstallResult = -14;
        this.mAppInstallProgress = 0;
        this.mAppRemoveResult = 5;
        this.mAppUpgradeResult = false;
        this.mAppInfo = null;
        this.mFileInstallResult = -1;
        this.mFileInstallUri = null;
        this.mFileInstallProgress = 0;
        this.mCoreDumpResult = -10;
        this.mCoreDumpFilename = null;
        this.mLogDumpResult = 0;
        this.mLogDumpFilename = null;
        this.mDevConnIpAddress = null;
        this.mDevConnIsConnected = false;
        this.mDevConnProxyConnected = false;
        this.mPebbleTimeConnected = false;
        this.mLastEvent = (EventType) in.readSerializable();
        this.mIsDiscoveryInProgress = in.readByte() != (byte) 0;
        if (in.readByte() != (byte) 0) {
            z = true;
        } else {
            z = false;
        }
        this.mIsBluetoothEnabled = z;
        this.mFirmwareInstallProgress = in.readInt();
        this.mFirmwareInstallResult = in.readInt();
        if (in.readByte() != (byte) 0) {
            z = true;
        } else {
            z = false;
        }
        this.mNotificationDemoResult = z;
        this.mAppInstallResult = in.readInt();
        this.mAppInstallProgress = in.readInt();
        this.mAppRemoveResult = in.readInt();
        if (in.readByte() != (byte) 0) {
            z = true;
        } else {
            z = false;
        }
        this.mAppUpgradeResult = z;
        this.mAppInfo = (AppInfo) in.readParcelable(AppInfo.class.getClassLoader());
        this.mFileInstallResult = in.readInt();
        this.mFileInstallUri = in.readString();
        this.mFileInstallProgress = in.readInt();
        this.mCoreDumpResult = in.readInt();
        this.mCoreDumpFilename = in.readString();
        this.mLogDumpResult = in.readInt();
        this.mLogDumpFilename = in.readString();
        this.mDevConnIpAddress = in.readString();
        this.mDevConnIsConnected = in.readByte() != (byte) 0;
        if (in.readByte() != (byte) 0) {
            z = true;
        } else {
            z = false;
        }
        this.mDevConnProxyConnected = z;
        if (in.readByte() == (byte) 0) {
            z2 = false;
        }
        this.mPebbleTimeConnected = z2;
        this.mStateListener = null;
    }
}
